package com.wsx.ones.monitor.core.codec;

import java.io.IOException;
import java.io.ObjectOutput;

/**
 * 抽象的实现序列化操作，供基础功能设计
 * Created by wangshuaixin on 17/2/4.
 */
public abstract class AbstractCodec implements Codec {

    protected void serialize(ObjectOutput output, Object message, Serialization serialization) throws IOException {
        if (null == message) {
            output.writeObject(null);
            return;
        }
        output.writeObject(serialization.serializ(message));
    }

    protected Object deserialize(byte[] bytes, Class<?> type, Serialization serialization) throws IOException {
        if (null == bytes) {
            return null;
        }
        return serialization.deserializ(bytes, type);
    }
}
